{{- define "status_resources" }}
cpu: 10m
memory: 25Mi
{{- end }}

{{- if (.Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: status
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "status")) | nindent 2 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: status
  updatePolicy:
    updateMode: "Auto"
  resourcePolicy:
    containerPolicies:
    - containerName: "status"
      minAllowed:
        {{- include "status_resources" . | nindent 8 }}
      maxAllowed:
        cpu: 20m
        memory: 50Mi
{{- end }}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: status
  namespace: d8-upmeter
  {{- include "helm_lib_module_labels" (list . (dict "app" "status")) | nindent 2 }}
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: status
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: status
  namespace: d8-{{ .Chart.Name }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "status")) | nindent 2 }}
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: status
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: status
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/status/configmap.yaml") . | sha256sum }}
    spec:
      imagePullSecrets:
        - name: deckhouse-registry
      terminationGracePeriodSeconds: 5
      enableServiceLinks: false
      {{- include "helm_lib_node_selector" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_priority_class" (tuple . "cluster-low") | nindent 6 }}
      {{ include "helm_lib_module_pod_security_context_run_as_user_deckhouse" . | nindent 6 }}
      containers:
        - name: status
          {{- include "helm_lib_module_container_security_context_read_only_root_filesystem" . | nindent 10 }}
          image: {{ include "helm_lib_module_image" (list . "status") }}
          lifecycle:
            preStop:
              exec:
                command: [ "/opt/nginx-static/sbin/nginx", "-s", "quit" ]
          ports:
          - name: http
            containerPort: 8080
            protocol: TCP
          - name: healthz
            containerPort: 10253
            protocol: TCP
          volumeMounts:
          - name: config
            mountPath: /opt/nginx-static/conf/nginx.conf
            subPath: nginx.conf
          - name: tmp
            mountPath: /tmp
          livenessProbe:
            httpGet:
              path: /healthz
              port: 10253
              scheme: HTTP
            initialDelaySeconds: 10
            timeoutSeconds: 5
          readinessProbe:
            httpGet:
              path: /
              port: 8080
              scheme: HTTP
            timeoutSeconds: 5
          resources:
            requests:
              {{- include "helm_lib_module_ephemeral_storage_logs_with_extra" 10 | nindent 14 }}
{{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
              {{- include "status_resources" . | nindent 14 }}
{{- end }}
      volumes:
      - name: config
        configMap:
          name: status
      - name: tmp
        emptyDir: {}
